<?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;
use App\Models\Tag;
use App\Services\TagService;
use Illuminate\Http\Request;
use Inertia\Inertia;

/**
 * 前台标签控制器
 * 
 * 职责：
 * - 处理前台标签相关的HTTP请求
 * - 调用 TagService 处理业务逻辑
 * - 返回视图
 */
class TagController extends Controller
{
    /**
     * 标签服务
     * 
     * @var TagService
     */
    protected TagService $tagService;

    /**
     * 构造器
     */
    public function __construct(TagService $tagService)
    {
        $this->tagService = $tagService;
    }

    /**
     * 显示标签页面
     */
    public function show(Tag $tag, Request $request)
    {
        // 调用服务层获取标签下的已发布文章
        $posts = $this->tagService->getTagPosts(
            $tag,
            $request->only(['search']),
            9
        );

        return Inertia::render('Blog/Tag', [
            'tag' => $tag,
            'posts' => $posts
        ]);
    }
} 